package com.dhl.factory.factorymethod.order;

import com.dhl.factory.factorymethod.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @title: OrderPizza
 * @Author danghailiang
 * @Date: 2022/7/27 21:07
 * @Version 1.0
 */
public abstract class OrderPizza {
    public OrderPizza() {
        Pizza pizza = null;
        String orderType;
        do {
            orderType = getType();
            pizza = this.createPizza(orderType);
            if(pizza == null){
                break;
            }
            pizza.prepare();
            pizza.bake();
            pizza.box();
            pizza.cut();

        } while (true);

    }

    /**
     * 创建pizza抽象方法
     * @param type
     * @return
     */
    public abstract Pizza createPizza(String type);

    public String getType() {
        // 控制台获取数据
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String type = null;
        try {
            type = bufferedReader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return type;
    }
}
